package com.guava.string;

import com.google.common.base.CharMatcher;

/**
 * CharMatcherTester--GuavaTest
 *
 * @author: Jovi
 * @createTime: 2018-05-11 14:51
 **/
public class CharMatcherTester {

    public static void main(String[] args) {
        System.out.println(CharMatcher.DIGIT.retainFrom("mahesh123")); // only the digits
        System.out.println(CharMatcher.WHITESPACE.trimAndCollapseFrom("     Mahesh     Parashar ", ' '));
        // trim whitespace at ends, and replace/collapse whitespace into single spaces
        System.out.println(CharMatcher.JAVA_DIGIT.replaceFrom("mahesh123", "*")); // star out all digits
        System.out.println(CharMatcher.JAVA_DIGIT.or(CharMatcher.JAVA_UPPER_CASE).retainFrom("mahesh123"));
        // eliminate all characters that aren't digits or lowercase

        // removerFrom
        String removeFromResult = CharMatcher.isNot('a').removeFrom("abacd");
        System.out.println("removeForm:" + removeFromResult);
        // retainFrom method
        String retainFormResult = CharMatcher.is('a').retainFrom("abacd");
        System.out.println("retainForm:" + retainFormResult);
        // replaceFrom method
        String replaceFormResult1 = CharMatcher.WHITESPACE.replaceFrom("a bcd",
                'f');
        System.out.println("replaceFrom_1:" + replaceFormResult1);
        String replaceFormResult2 = CharMatcher.DIGIT.replaceFrom("a3bcd",
                "Three");
        System.out.println("replaceFrom_2:" + replaceFormResult2);
        // trimFrom
        String trimFromResult = CharMatcher.anyOf("ab").trimFrom("abacatabb");
        System.out.println("trimFrom:" + trimFromResult);
        // trimLeadingFrom
        String trimLeadingFromResult = CharMatcher.anyOf("ab").trimLeadingFrom(
                "abacatabb");
        System.out.println("trimLeadingFrom:" + trimLeadingFromResult);
        // trimTrailingFrom
        String trimTrailingFromResult = CharMatcher.anyOf("ab")
                .trimTrailingFrom("abacatabb");
        System.out.println("trimTrailingFrom:" + trimTrailingFromResult);
        // collapseFrom
        String collapseFromResult = CharMatcher.anyOf("bre").collapseFrom(
                "bookkeeeeeeeper", '-');
        System.out.println("collapseFrom:" + collapseFromResult);
        // trimAndCollapseFrom
        String trimAndCollapseFromResult = CharMatcher.anyOf("bre")
                .trimAndCollapseFrom("bookkeeper", '-');
        System.out.println("trimAndCollapseFrom:" + trimAndCollapseFromResult);
        // matchesAllOf
        boolean matchesAllOfResult = CharMatcher.JAVA_UPPER_CASE
                .matchesAnyOf("hcd");
        System.out.println("matchesAnyOf:" + matchesAllOfResult);
        // or and negate
        String orResult = CharMatcher.JAVA_DIGIT
                .or(CharMatcher.JAVA_UPPER_CASE).retainFrom("dd59cF");
        System.out.println("or:" + orResult);
        // negate
        String negateResult = CharMatcher.JAVA_DIGIT.negate().retainFrom(
                "dd59cF");
        System.out.println("negate:" + negateResult);
    }
}
